package com.marketingexpert.service.marketingmgnt.impl;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.dao.DataAccessException;

import com.marketingexpert.config.Placeholder;
import com.marketingexpert.dao.MarketingDao;
import com.marketingexpert.domain.AutoFollowsFans;
import com.marketingexpert.domain.AutoRecomment;
import com.marketingexpert.domain.AutoatContent;
import com.marketingexpert.domain.Trend;
import com.marketingexpert.domain.UserFuncEnable;
import com.marketingexpert.domain.UserFuncEnableWeiboId;
import com.marketingexpert.exception.MarketingExpertException;
import com.marketingexpert.service.marketingmgnt.MarketingService;
import com.marketingexpert.service.snsmgnt.User;
import com.marketingexpert.service.storemgnt.AbstractActivity;
import com.marketingexpert.service.storemgnt.MarketingItem;
import com.marketingexpert.service.storemgnt.MarketingPromotion;
import com.taobao.api.domain.Coupon;
import com.taobao.api.domain.Item;
import com.taobao.api.domain.Meal;

public class MarketingServiceDBImpl extends MarketingServiceBaseImpl {

	private static Logger logger = Logger.getLogger(MarketingServiceDBImpl.class); 
	
	private MarketingDao marketingDao;
	
	@Override
	public boolean deleteAutoFollowedFansByPid(int parentUserId)
			throws MarketingExpertException {
		try {
			return getMarketingDao().deleteAutoFollowedFansByPid(parentUserId);
		} catch (DataAccessException e) {
			logger.error(e.getMessage(), e);
			throw new MarketingExpertException(e);
		}
		
	}
	

	@Override
	public List<AutoFollowsFans> queryAllAutoFollowFansByPId(int parentUserId,int pageNo)
			throws MarketingExpertException {
		try {
			return getMarketingDao().queryAllAutoFollowFansByPId(parentUserId,pageNo);
		} catch (DataAccessException e) {
			logger.error(e.getMessage(), e);
			throw new MarketingExpertException(e);
		}
	}

	@Override
	public int saveAutoFollowedFans(AutoFollowsFans autoFollowsFnas)
			throws MarketingExpertException {
		try {
			return getMarketingDao().saveAutoFollowedFans(autoFollowsFnas);
		} catch (DataAccessException e) {
			logger.error(e.getMessage(), e);
			throw new MarketingExpertException(e);
		}
	}

	public MarketingDao getMarketingDao() {
		return marketingDao;
	}

	public void setMarketingDao(MarketingDao marketingDao) {
		this.marketingDao = marketingDao;
	}

	@Override
	public int queryNewFansCount(int id) {
		try {
			return getMarketingDao().queryNewFansCount(id);
		} catch (DataAccessException e) {
			logger.error(e.getMessage(), e);
			throw new MarketingExpertException(e);
		}
	}

	@Override
	public List<Trend> queryAllTrendByPId(int pid) {
		try {
			return getMarketingDao().queryAllTrendByPId(pid);
		} catch (DataAccessException e) {
			logger.error(e.getMessage(), e);
			throw new MarketingExpertException(e);
		}
		
	}

	@Override
	public void cancelAutoMarketing(int pid) {
		try {
			getMarketingDao().cancelAutoMarketing(pid);
		} catch (DataAccessException e) {
			logger.error(e.getMessage(), e);
			throw new MarketingExpertException(e);
		}
	}

	@Override
	public AutoatContent queryAtcontent(int pId) {
		try {
			return getMarketingDao().queryAtcontent(pId);
		} catch (DataAccessException e) {
			logger.error(e.getMessage(), e);
			throw new MarketingExpertException(e);
		}
	}

	@Override
	public int saveAutoAtContent(AutoatContent atContent) {
		try {
			return getMarketingDao().saveAutoAtContent(atContent);
		} catch (DataAccessException e) {
			logger.error(e.getMessage(), e);
			throw new MarketingExpertException(e);
		}
	}

	@Override
	public int updateAtcontent(AutoatContent atContent) {
		try {
			return getMarketingDao().updateAtcontent(atContent);
		} catch (DataAccessException e) {
			logger.error(e.getMessage(), e);
			throw new MarketingExpertException(e);
		}
	}

	@Override
	public void cancelAutoAtContent(int atContentId) {
		try {
			getMarketingDao().cancelAutoAtContent(atContentId);
		} catch (DataAccessException e) {
			logger.error(e.getMessage(), e);
			throw new MarketingExpertException(e);
		}
	}

	@Override
	public void saveFuncEnable(UserFuncEnable ufe) {
		try {
			marketingDao.saveFuncEnable(ufe);
		} catch(DataAccessException e) {
			throw new MarketingExpertException(e);
		}
	}

	@Override
	public UserFuncEnable queryEnabledFunc(String funcCode, int userId) {
		try {
			return marketingDao.queryEnabledFunc(funcCode,userId);
		} catch(DataAccessException e) {
			throw new MarketingExpertException(e);
		}
	}

	@Override
	public void disableFunc(int funcId, int userId) {
		try {
			marketingDao.disableFunc(funcId,userId);
		} catch(DataAccessException e) {
			throw new MarketingExpertException(e);
		}
	}

	@Override
	public void updateFunc(List<UserFuncEnableWeiboId> userFuncEnableWeiboIds,
			int pid) {
		try {
			marketingDao.updateFunc(userFuncEnableWeiboIds, pid);
		} catch(DataAccessException e) {
			throw new MarketingExpertException(e);
		}
	}

	@Override
	public int enableAutoAt(UserFuncEnable ufe) {
		try {
			return marketingDao.enableAutoAt(ufe);
		} catch(DataAccessException e) {
			throw new MarketingExpertException(e);
		}
	}

	@Override
	public void disableAutoAt(int parseInt) {
		try {
			marketingDao.disableAutoAt(parseInt);
		} catch(DataAccessException e) {
			throw new MarketingExpertException(e);
		}
	}	
	
	
}
